﻿#region License
// (c) Intergen.
// This source is subject to the Microsoft Public License (Ms-PL).
// Please see http://go.microsoft.com/fwlink/?LinkID=131993 for details.
// All other rights reserved.
#endregion

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Collections.ObjectModel;

namespace TextGlow.Control.Utilities
{
  public class DelegateKeyedCollection<TKey, TItem> : KeyedCollection<TKey, TItem>
  {
    private readonly Func<TItem, TKey> _itemKeyGetter;

    public DelegateKeyedCollection(Func<TItem, TKey> itemKeyGetter)
    {
      if (itemKeyGetter == null)
        throw new ArgumentNullException("itemKeyGetter");

      _itemKeyGetter = itemKeyGetter;
    }

    protected override TKey GetKeyForItem(TItem item)
    {
      return _itemKeyGetter(item);
    }
  }
}